package com.oocl.batchdatav2.util;

import java.util.regex.Pattern;

public class StringValidator {
	
	private static final String SPLITTER_REGEX = "\\s+";
	private static final String ID_REGEX = "\\d+";
	private static final String NAME_REGEX = ".*";
	private static final String EMAIL_REGEX = "(\\w)+(\\.\\w+)*@(\\w)+((\\.\\w+)+)";
	private static final String SEX_REGEX = "(true|false)";
	private static final String DATE_REGEX = "((19\\d{2})|(200\\d)|(201[0-7]))(?<sp>\\-|\\/)((0?[1-9])|(1[0-2]))(\\k<sp>)((0?[1-9])|([1-2]\\d)|(30))";

	public static boolean validateLine(String line) {
		StringBuilder regex = new StringBuilder("^").append(ID_REGEX).append(SPLITTER_REGEX).append(NAME_REGEX)
				.append(SPLITTER_REGEX).append(EMAIL_REGEX).append(SPLITTER_REGEX).append(SEX_REGEX)
				.append(SPLITTER_REGEX).append(DATE_REGEX);
		return Pattern.compile(regex.toString()).matcher(line).find();
	}
}
